import 'package:lx_widgets_library/http/base_data.dart';
import 'package:safemap/safemap.dart';

// http响应模型
class HttpResponseModel extends BaseData {
  // 原始数据
  Map<String, dynamic> originData;

  // 图形验证码URL
  String captchaUrl;

  // 安全令牌
  String securityToken;

  // 验证码校验成功后返回的token
  String verifyToken;

  // 最新骑行记录ID
  int latestRideRecordId;

  // 所属地区
  String region;

  // 所属地区的area
  String area;

  // 所属地区的phoneCode
  String phoneCode;

  // 车辆是否可用（服务端判断车辆是否被盗等策略）
  bool vehicleAvailable;

  // 云盒是否已激活
  bool tboxActivated;

  HttpResponseModel({
    this.captchaUrl = "",
    this.securityToken = "",
    this.verifyToken = "",
    this.latestRideRecordId = 0,
    this.originData = const {},
    this.phoneCode = "",
    this.region = "",
    this.area = "",
    this.vehicleAvailable = false,
    this.tboxActivated = false,
  });

  factory HttpResponseModel.fromJson(Map<String, dynamic> json) {
    SafeMap safeMap = SafeMap(json);
    return HttpResponseModel(
      originData: json,
      captchaUrl: safeMap['location'].string ?? "",
      securityToken: safeMap['token'].string ?? "",
      verifyToken: safeMap['token'].string ?? "",
      latestRideRecordId: safeMap['id'].toInt ?? 0,
      phoneCode: safeMap['geo'].map?['phone_code'] ?? "",
      region: safeMap['region'].string ?? "",
      area: safeMap['area'].string ?? "",
      vehicleAvailable: safeMap['state'].toInt == 1,
      tboxActivated: safeMap['tbox_activated'].boolean,
    );
  }
}
